package site.yunnong.atvris.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import site.yunnong.atvris.common.api.Page;
import site.yunnong.atvris.common.api.ResultVO;
import site.yunnong.atvris.common.dto.NewQueryParam;
import site.yunnong.atvris.common.dto.NewSaveParam;
import site.yunnong.atvris.portal.service.NewsService;
import site.yunnong.atvris.service.vo.NewsVO;

import javax.annotation.Resource;


/**
 * @author zhangjinghao
 * @email jhzhang9102@163.com
 * @date 2021-07-09 23:45:37
 */
@Api("动态相关接口")
@RestController
@RequestMapping("/news")
public class NewsController {

    @Resource
    private NewsService newsService;

    /**
     * 列表
     */
    @ApiOperation("分页查询个人动态列表")
    @PostMapping("/list")
    public ResultVO list(@RequestBody NewQueryParam param){
        Page<NewsVO> result = newsService.queryPage(param);
        return new ResultVO().success(result);
    }

    /**
     * todo 保存，推送相关关注人
     */
    @ApiOperation("保存动态")
    @PostMapping("/save")
    public ResultVO save(@RequestBody NewSaveParam param){
        NewsVO vo = newsService.save(param);
        return new ResultVO().success(vo);
    }

//    /**
//     * 修改
//     */
//    @PostMapping("/update")
//    public ResultVO update(@RequestBody NewsUpdateParam param){
//		newsService.update(param);
//        return new ResultVO().success();
//    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public ResultVO delete(@RequestParam("unid") Long unid){
		newsService.removeByUnid(unid);
        return new ResultVO().success();
    }

    /**
     * 关注的人动态分页列表
     */
    @ApiOperation("分页查自己和关注的人的动态")
    @PostMapping("/follow-news-list")
    public ResultVO followNewsList(@RequestBody NewQueryParam param){
        Page<NewsVO> result = newsService.queryFollowNewsPage(param);
        return new ResultVO().success(result);
    }

}
